# -*- coding: utf-8 -*-
"""
# @created on : 9月 2021/9/26 09:13
# @author     : kevin
# @file       : run_case.py
# @software   : PyCharm
# @project    : auto_keyword_data


@license: (C) Copyright 2019-2025, Corporation Limited.
@desc:
"""
import unittest
from base.get_data import GetData
from base.web_key import WebKey
from common.log import Logger
from ddt import ddt, data, file_data, unpack

case_data = (GetData(sheet_name='suit').get_test_case())


@ddt
class RunSuit(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        RunSuit.driver = None
        RunSuit.pass_count = 0
        RunSuit.fill_count = 0

    @classmethod
    def tearDownClass(cls) -> None:
        RunSuit.driver.close()

    def setUp(self) -> None:
        pass

    def tearDown(self) -> None:
        pass

    @data(*case_data)
    @unpack
    def test_login(self, suit_name, case_step, methods, key, path, value, assertion, description):
        log = Logger()
        print(f'执行步骤：{case_step},操作方法：{methods}，定位方式为：{key},'
                                   f'查找元素为：{path},输入值为：{value}， 断言为 {assertion}')
        if methods is not None:
            log.logger('info', f'开始执行{suit_name}')
            params = {}
            params['测试步骤'] = case_step
            params['定位方式'] = key
            params['定位路径'] = path
            params['输入值'] = value
            params['断言'] = assertion
            if methods == 'browser':
                RunSuit.driver = WebKey(value)
            elif assertion:
                res = getattr(RunSuit.driver, methods)(**params)
                if res:
                    log.logger('info', f'执行断言{assertion}成功')
                    RunSuit.pass_count += 1
                else:
                    log.logger('error', f'执行断言{assertion}失败')
                    RunSuit.fill_count += 1
                    raise AssertionError
            else:
                log.logger('info', f'执行步骤：{case_step},操作方法：{methods}，定位方式为：{key},'
                                   f'查找元素为：{path},输入值为：{value}， assertion is {assertion}')
                getattr(RunSuit.driver, methods)(**params)


if __name__ == '__main__':
    unittest.main()
